<template>
  <div>
    <el-card style="height: calc(100vh - 110px)">
      <!-- 头部功能区 -->
      <el-row>
        <el-form inline :model="query" ref="ruleForm">
          <!-- 新增搜索 -->
          <el-form-item>
            <el-input
              placeholder="请输入设备IP"
              style="width: 200px"
              size="mini"
              v-model="query.ip"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="getListData()"
              >搜索</el-button
            >
          </el-form-item>
        </el-form>
      </el-row>
      <!-- 编辑弹框 -->
      <el-dialog title="编辑">
        <el-form ref="editForm">
          <el-form-item label="备注" prop="remark" label-width="100px">
            <el-input
              autocomplete="off"
              placeholder="请输入备注信息"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button>取 消</el-button>
          <el-button type="primary">确定</el-button>
        </div>
      </el-dialog>
      <!-- 编辑弹框 -->
      <el-row>
        <el-dialog title="编辑" :visible.sync="dialogFormVisible">
          <el-form ref="form" :model="form">
            <el-form-item label="备注" label-width="100px">
              <el-input
                autocomplete="off"
                placeholder="请输入备注信息"
                v-model="form.remark"
              ></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="edit('form')">确定</el-button>
          </div>
        </el-dialog>
      </el-row>
      <!-- 列表 -->
      <el-row>
        <el-table
          :data="tableData"
          style="width: 100%"
          height="calc(100vh - 250px)"
          :cell-style="cellStyle"
          :default-sort="{ prop: 'date', order: 'descending' }"
        >
          <el-table-column
            show-overflow-tooltip="ture"
            prop="ip"
            label="设备IP"
            align="center"
            width="140"
          >
            <template slot-scope="scope">
              <el-tag type="danger">{{ scope.row.ip }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip="ture"
            prop="systemName"
            align="center"
            label="系统名称"
          >
          </el-table-column>

          <!-- <el-table-column show-overflow-tooltip="ture"
                                     prop="exitFlux"
                                     align="center"
                                     label="出口流量">
                    </el-table-column>
                    <el-table-column show-overflow-tooltip="ture"
                                     prop="intoFlux"
                                     align="center"
                                     label="入口流量">
                    </el-table-column>
                    <el-table-column show-overflow-tooltip="ture"
                                     prop="exitRate"
                                     align="center"
                                     width="150"
                                     label="出口速率">
                    </el-table-column>
                    <el-table-column show-overflow-tooltip="ture"
                                     prop="intoRate"
                                     align="center"
                                     label="入口速率">
                    </el-table-column> -->
          <el-table-column
            show-overflow-tooltip="ture"
            prop="cpu"
            align="center"
            label="CPU%"
          >
            <template slot-scope="scope">
              <el-tag type="primary">{{ scope.row.cpu }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            show-overflow-tooltip="ture"
            prop="memory"
            align="center"
            label="内存%"
          >
            <template slot-scope="scope">
              <el-tag type="primary">{{ scope.row.memory }}</el-tag>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="status" align="center" label="监控状态">
                        <template slot-scope="scope">
                            <el-tag type="primary">{{ scope.row.status | getstatus }}</el-tag>
                        </template>
                    </el-table-column> -->
          <el-table-column
            show-overflow-tooltip="ture"
            prop="updateTime"
            width="160"
            align="center"
            label="更新时间"
          >
          </el-table-column>
          <el-table-column
            show-overflow-tooltip="ture"
            prop="tag"
            align="center"
            label="标签"
          >
          </el-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="query.pageNum"
          :limit.sync="query.pageSize"
          :select-data-len="multipleSelection.length"
          @pagination="getListData()"
        />
      </el-row>
    </el-card>
  </div>
</template>
<script>
import {
  getqueryApi,
  delganwangApi,
  editganwangApi,
} from "@/api/dataPresentation/alarmCategory.js";
export default {
  data() {
    return {
      options: [
        {
          value: 0,
          label: "在线",
        },
        {
          value: 1,
          label: "下线",
        },
      ],
      total: 0,
      tableData: [],
      multipleSelection: [], //多选
      dialogFormVisible: false,
      query: {
        ip: null, //ip
        status: null,
      },
      form: {
        remark: null,
      },
    };
  },
  methods: {
    //编辑
    AddAssociationType(row) {
      console.log(row);
      this.dialogFormVisible = true;
      this.form = row;
    },
    edit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let res = await editganwangApi(this.form);
          let { code, msg } = res;
          if (code == 200) {
            this.$message.success(msg);
            this.getListData();
            this.dialogFormVisible = false;
          } else {
            this.$message.error(msg);
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    getListData() {
      getqueryApi(this.query).then((res) => {
        this.tableData = res.data.date;
        this.total = res.data.total;
      });
    },
    //删除数据
    Del(networkId) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          delganwangApi(networkId)
            .then((res) => {
              this.getListData();
              this.$message.success("删除成功");
            })
            .catch((error) => {});
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  created() {
    this.getListData();
  },
  filters: {
    getstatus(val) {
      switch (val) {
        case 0:
          return "监控中";
        case 1:
          return "未监控";
        case 2:
          return "未知";
      }
    },
  },
  computed: {},
};
</script>
<style lang="scss" scoped></style>
